package struct;

import javax.swing.tree.TreeNode;

public class LinkList {
	public static ListNode generateLinkList(int[] arr) {
		if (arr == null || arr.length == 0) {
			return null;
		}
		ListNode head = new ListNode(0);//创建一个头结点
		ListNode cur = head;
		for (int i = 0; i < arr.length; i++) {
			cur.next = new ListNode(arr[i]);
			cur = cur.next;
		}
		return head.next;
	}

	public static void printLinkList(ListNode head) {
		ListNode cur = head;
		while (cur != null) {
			System.out.print(cur.val + " ");
			cur = cur.next;
		}
		System.out.println();
	}

	public static void main(String[] args) {
		ListNode linkList = generateLinkList(new int[]{1, 2, 3, 4});
		System.out.println(linkList);
	}


}
